package com.cdatos.golGana.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.cdatos.golGana.model.base.PersistentEntity;

@Entity
@Table(name = "USUARIO", uniqueConstraints = {@UniqueConstraint(columnNames={"nick"})})
public class Usuario extends PersistentEntity implements Serializable {

	/**
	 */
	private static final long serialVersionUID = 450750056327497251L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
	
    @Column(name="NICK", nullable=false, length=20)
	private String nick;
	
    @Column(name="CONTRASENIA", nullable=false, length=20)
	private String contrasenia;
	
    @Column(name="PUNTOS")
	private Long puntos;
    
	@Column(name = "EMAIL", nullable = false, length = 50)
	private String email;

	@ManyToMany(cascade = { CascadeType.MERGE, CascadeType.REFRESH,
			CascadeType.PERSIST })
	private List<Rol> roles = new ArrayList<Rol>();
	
    @ManyToMany(targetEntity=com.cdatos.golGana.model.Grupo.class,
			cascade = { CascadeType.MERGE, CascadeType.REFRESH,	CascadeType.PERSIST })
	@JoinTable(name="USUARIO_GRUPO",
        joinColumns=@JoinColumn(name="USUARIO_ID"),
        inverseJoinColumns=@JoinColumn(name="GRUPO_ID"))
	private List<Grupo> grupos;
	
	@OneToMany(mappedBy = "usuario", cascade = { CascadeType.MERGE,CascadeType.REFRESH })
    private List<Prediccion> predicciones;
    
	
	
    public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getNick() {
		return nick;
	}
	public void setNick(String nick) {
		this.nick = nick;
	}
	public String getContrasenia() {
		return contrasenia;
	}
	public void setContrasenia(String contrasenia) {
		this.contrasenia = contrasenia;
	}
	public List<Grupo> getGrupos() {
		return grupos;
	}	
	public void setGrupos(List<Grupo> grupos) {
		this.grupos = grupos;
	}
	public void setPuntos(Long puntos) {
		this.puntos = puntos;
	}
	public Long getPuntos() {
		return puntos;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public List<Rol> getRoles() {
		return roles;
	}
	public void setRoles(List<Rol> roles) {
		this.roles = roles;
	}
	public void setPredicciones(List<Prediccion> predicciones) {
		this.predicciones = predicciones;
	}
	public List<Prediccion> getPredicciones() {
		return predicciones;
	}
	
	
	@Override
	public String toString() {
		return id + " " + nick + " " + contrasenia;
	}

	public Usuario() {
	}
	
}
